import turbogears   as tg

import logging
import cherrypy
import sqlobject
import kaizen.model as model

from kaizen.model import Action, Tag, Project, Context,session
from turbogears import identity, expose, validate, validators, redirect, error_handler, flash, widgets, view
from formencode import validators
from turbogears.widgets import DataGrid

log = logging.getLogger("kaizen.subcontrollers.tag")

class SandboxController:

    @expose(template="kaizen.templates.textilizeResult", content_type='text/html; charset=utf-8')
    @error_handler()
    def textilize(self, text, tg_errors=None, **keywords):
        return dict(text=text)

    @expose(template="kaizen.templates.datagrid", content_type='text/html; charset=utf-8')
    @error_handler()
    def viewDatagrid(self, tg_errors=None, **keywords):
        projectForm =  DataGrid(fields=[('Title', 'title')])
        projects = session.query(Project).select()
        return dict(form=projectForm, data=projects)

    @expose(template="kaizen.templates.datagrid", content_type='text/html; charset=utf-8')
    @error_handler()
    def viewDatagridOld(self, tg_errors=None, **keywords):
        projects = session.query(Project).select()
        grid = DataGrid(fields=[('Name', lambda row: row[1]),
                                  ('Country', lambda row: row[2]),
                                  ('Age', lambda row: row[0])],
                          default=[(33, "Anton Bykov", "Bulgaria"),
                                   (23, "Joe Doe", "Great Britain"),
                                   (44, "Pablo Martelli", "Brazil")])
        return dict(grid=grid)
